package com.clqteam.daoimpl;
/**
 * 展示会员的信息
 * @author Administrator
 *LXG
 */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.clqteam.dao.ShowVIPDao;
import com.clqteam.model.Supplier;
import com.clqteam.model.VIP;
import com.clqteam.util.JDBCutil;


/**
 * 信息总数
 * @return int
 */
public class ShowVIPDaoImpl implements ShowVIPDao{


	@Override
	public int countVIP() {
		int count=0;
		StringBuffer sql=new StringBuffer("");
		sql.append(" SELECT COUNT(s_vip.vId) AS tota");
		sql.append(" FROM s_vip");
			
		Connection con=JDBCutil.getConnection();
		try {
			PreparedStatement ps=con.prepareStatement(sql.toString());			
			ResultSet rs=ps.executeQuery();
			if(rs.next()){
				count=rs.getInt("tota");
			}
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}
	/**
	 * 按页展示信息
	 * @param page 页面
	 * @param rows 页面大小
	 * @return list
	 */
	@Override
	public List<VIP> showVIP(int page, int rows) {
		List <VIP>li=new ArrayList();
		StringBuffer sql=new StringBuffer("");
		sql.append(" SELECT s_vip.vId,s_vip.vPoint,s_vip.pitRate,s_vip.vDiscount,s_vip.vTime");
		sql.append(" FROM s_vip");
		sql.append(" LIMIT ?,?");	
		Connection con=JDBCutil.getConnection();
		try {
			PreparedStatement ps=con.prepareStatement(sql.toString());
			ps.setInt(1, (page-1)*rows);
			ps.setInt(2, rows);
			ResultSet rs=ps.executeQuery();
			while(rs.next()){
				VIP v=new VIP();
				v.setvId(rs.getInt("vId"));
				v.setvPoint(rs.getInt("vPoint"));
				v.setPitRate(rs.getDouble("pitRate"));
				v.setvDiscount(rs.getDouble("vDiscount"));
				v.setvTme(rs.getString("vTime"));
				li.add(v);
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return li;
	}

}
